package cn.net.ecode.tools.ecodeplatformmaker.model;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import cn.net.ecode.tools.ecodeplatformmaker.util.OperateXml;

public class ListConn {

	public List list = new ArrayList();

	public interface Listener {
		public void add(Map conn);

		public void remove(Map conn);
	}

	private Listener listener;

	public ListConn() {
		try {
			list = (ArrayList) OperateXml.readAllNodesFromXmlFile(System.getProperty("user.dir") + "/Connection.xml");
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public void setListener(Listener listener) {
		this.listener = listener;
	}

	public void add(HashMap conn) {
		list.add(conn);
		if (listener != null) {
			listener.add(conn);
		}
	}

	public void remove(HashMap conn) {
		list.remove(conn);
		if (listener != null) {
			listener.remove(conn);
		}
	}

	public List elements() {
		return list;
	}
}